﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using BaseData.Annotations;
using BaseData.Models;

namespace BaseData.Exts
{
    public class Ext_News_All_Field_Node_Infox
    {
        public Ext_News_All_Field_Node_Infox()
        {
            this.Parent = new Web_Base_News_Node();
            this.Node = new Web_Base_News_Node();
            this.Info = new Web_Base_News_Info();
        }
        public Web_Base_News_Node Parent { get; set; }
        public Web_Base_News_Node Node { get; set; }
        public Web_Base_News_Info Info { get; set; }
    }

    public class Ext_Book_Tables
    {
        public Ext_Book_Tables()
        {
            this.Info1 = new Web_Base_Book_Info();
            this.Info2 = new Web_Base_Book_Info();
        }
        public Web_Base_Book_Info Info1 { get; set; }
        public Web_Base_Book_Info Info2 { get; set; }
    }

    public class Ext_Book_Tagx
    {
        public List<Ext_Book_Tagx> Get(List<Ext_Book_Tables> items)
        {
            var temp = new List<Ext_Book_Tagx>();
            foreach (var item in items)
            {
                temp.Add(new Ext_Book_Tagx()
                {
                    PkId1 = item.Info1.PkId,
                    Title1 = item.Info1.Title,
                    Content1 = item.Info1.Content,
                    DateTimeCreate1 = item.Info1.DateTimeCreate,
                    PkId2 = item.Info2 != null ? item.Info2.PkId : 0,
                    Title2 = item.Info2 != null ? item.Info2.Title : "",
                    Content2 = item.Info2 != null ? item.Info2.Content : "",
                    DateTimeCreate2 = item.Info2 != null ? item.Info2.DateTimeCreate : null,
                });
            }
            return temp;
        }
        // Info1
        public Nullable<int> PkId1 { get; set; }
        public string Title1 { get; set; }
        public string Content1 { get; set; }
        public Nullable<System.DateTime> DateTimeCreate1 { get; set; }
        // Info2
        public Nullable<int> PkId2 { get; set; }
        public string Title2 { get; set; }
        public string Content2 { get; set; }
        public Nullable<System.DateTime> DateTimeCreate2 { get; set; }
    }

    public class Ext_News_All_Field_Set : Ext_News_All_Tagx_Infos
    {
        public List<Ext_News_All_Tagx_Infos> Get(IEnumerable<Ext_News_All_Field_Node_Infox> items, [NotNull] List<Ext_News_All_Tagx_Infos> list)
        {
            if (list == null) throw new ArgumentNullException("list");
            var infos = new Ext_News_All_Field_Node_Infox().Info.GetType().GetFields();
            foreach (FieldInfo info in infos)
            {
                /// if (info.Name == dcol.ColumnName)
                /// {
                ///     if (dr[info.Name] == DBNull.Value) continue;
                ///     info.SetValue(sdto, dr[info.Name]);
                /// }
            }
            foreach (var item in items)
            {
                list.Add(new Ext_News_All_Tagx_Infos()
                {
                });
            }
            return list;
        }
    }
}
